﻿'Description:工装工具热处理记录/渗碳炉批--数据类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:Longb
'create Date:2022-9-26
'Rewriter:
'Rewrite Date:
Imports DatabaseAccess.DBUtility
''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Public Class GZHeatRecordInfoBusiness
    ''' <summary>
    ''' 保存热处理记录
    ''' </summary>
    ''' <param name="base"></param>
    ''' <param name="spec"></param>
    ''' <param name="dringno"></param>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SaveHeatRecordInfo(ByVal base As DataTable, ByVal spec As DataTable, ByVal dringno As DataTable, ByVal para As Dictionary(Of String, String)) As Boolean
        Dim arrList As New ArrayList
        Dim GZHEATRECORDINFOID As String = Guid.NewGuid().ToString
        arrList.Add(String.Format("delete from GZHEATRECORDINFODETAIL where GZHEATRECORDINFOID IN( select GZHEATRECORDINFOID from GZHEATRECORDINFO where CONTAINERID='{0}')", para("CONTAINERID")))
        arrList.Add(String.Format("delete from GZHEATRECORDINFODETAIL2 where GZHEATRECORDINFOID IN( select GZHEATRECORDINFOID from GZHEATRECORDINFO where CONTAINERID='{0}')", para("CONTAINERID")))
        arrList.Add(String.Format("delete from GZHEATRECORDINFO where CONTAINERID='{0}'", para("CONTAINERID")))
        Dim baseStr As String = <string>INSERT INTO GZHEATRECORDINFO (GZHEATRECORDINFOID,CONTAINERID,MATERIALNAME,SPECNAME,RESOURCENAME,HEATRECORDDATE,CREATEDATE,CREATEEMPLOYEEID) 
                                    VALUES('{0}','{1}','{2}','{3}', '{4}',to_date('{5}','yyyy-MM-dd'),sysdate,'{6}')</string>
        arrList.Add(String.Format(baseStr, GZHEATRECORDINFOID, para("CONTAINERID"), base(0)("MATERIALNAME"), base(0)("SPECNAME"), base(0)("RESOURCENAME"), base(0)("HEATRECORDDATE"), para("CREATEEMPLOYEEID")))

        For Each row As DataRow In spec.Rows
            Dim specStr As String = <string>INSERT INTO GZHEATRECORDINFODETAIL(GZHEATRECORDINFODETAILID,GZHEATRECORDINFOID,SHOVECHARGETEMPERATURE,SHOVECHARGETIME,KEEPWARMTEMPERATURE,HEATTOTEMPERATURETIME,OUTCHARGETIME,COOLANT,CREATEDATE,CREATEEMPLOYEEID)
                                    VALUES('{0}','{1}','{2}','{3}', '{4}', '{5}', '{6}', '{7}', sysdate, '{8}')
                                    </string>
            arrList.Add(String.Format(specStr, Guid.NewGuid().ToString, GZHEATRECORDINFOID, row("SHOVECHARGETEMPERATURE"), row("SHOVECHARGETIME"), row("KEEPWARMTEMPERATURE"), row("HEATTOTEMPERATURETIME"), row("OUTCHARGETIME"), row("COOLANT"), para("CREATEEMPLOYEEID")))
        Next

        For Each row As DataRow In dringno.Rows
            Dim dgStr As String = <string> INSERT INTO IN1.GZHEATRECORDINFODETAIL2(GZHEATRECORDINFODETAIL2ID, GZHEATRECORDINFOID, DRAWINGNO, CREATEDATE, CREATEEMPLOYEEID)
                                    VALUES('{0}','{1}','{2}',sysdate,'{3}')</string>
            arrList.Add(String.Format(dgStr, Guid.NewGuid().ToString, GZHEATRECORDINFOID, row("DRAWINGNO"), para("CREATEEMPLOYEEID")))
        Next

        Return DatabaseHelper.ExecuteSqlListTran(arrList)
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="CONTAINERID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetHeatRecordInfo(ByVal CONTAINERID As String) As DataSet
        Dim ds As DataSet = New DataSet
        Dim baseStr As String = String.Format("select MATERIALNAME,SPECNAME,RESOURCENAME,to_char(HEATRECORDDATE,'yyyy-MM-dd') HEATRECORDDATE from GZHEATRECORDINFO where CONTAINERID='{0}'", CONTAINERID)
        Dim base As DataTable = DatabaseHelper.Query_ReturnDatTable(baseStr)
        base.TableName = "base"
        ds.Tables.Add(base)

        Dim specStr As String = String.Format("select * from GZHEATRECORDINFODETAIL where GZHEATRECORDINFOID IN( select GZHEATRECORDINFOID from GZHEATRECORDINFO where CONTAINERID='{0}') ORDER BY SHOVECHARGETEMPERATURE ", CONTAINERID)
        Dim spec As DataTable = DatabaseHelper.Query_ReturnDatTable(specStr)
        spec.TableName = "spec"
        ds.Tables.Add(spec)

        Dim dgStr As String = String.Format("select * from GZHEATRECORDINFODETAIL2 where GZHEATRECORDINFOID IN( select GZHEATRECORDINFOID from GZHEATRECORDINFO where CONTAINERID='{0}')", CONTAINERID)
        Dim dg As DataTable = DatabaseHelper.Query_ReturnDatTable(dgStr)
        dg.TableName = "dg"
        ds.Tables.Add(dg)

        Return ds
    End Function

    ''' <summary>
    ''' 查询--渗碳炉批记录
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GZSTContainerRecord(ByVal para As Dictionary(Of String, String)) As DataSet
        Dim ds As DataSet = New DataSet
        Dim baseStr As String = String.Format(" select e.FULLNAME CREATEEMPLOYEE,to_char(st.STDATE,'yyyy-MM-dd') STDATE,st.SAMPLENO from GZSTCONTAINERRECORD st LEFT JOIN EMPLOYEE e ON e.EMPLOYEEID =st.CREATEEMPLOYEEID where CONTAINERID='{0}'", para("CONTAINERID"))
        Dim base As DataTable = DatabaseHelper.Query_ReturnDatTable(baseStr)
        base.TableName = "base"
        ds.Tables.Add(base)

        Dim dgStr As String = String.Format("select * from GZSTCONTAINERRECORDDETAIL where GZSTCONTAINERRECORDID IN( select GZSTCONTAINERRECORDID from GZSTCONTAINERRECORD where CONTAINERID='{0}') ORDER BY CREATEDATE", para("CONTAINERID"))
        Dim dg As DataTable = DatabaseHelper.Query_ReturnDatTable(dgStr)
        dg.TableName = "dg"
        ds.Tables.Add(dg)

        Return ds
    End Function

    ''' <summary>
    ''' 新增--渗碳炉批记录/图号
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function AddDrawingNo(ByVal para As Dictionary(Of String, String)) As Boolean
        Dim arrList As New ArrayList
        Dim GZSTCONTAINERRECORDID As String = Guid.NewGuid().ToString
        Dim str As String = <string>SELECT * FROM GZSTContainerRecord WHERE CONTAINERID='{0}'</string>
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format(str, para("CONTAINERID")))
        If dt.Rows.Count = 0 Then
            Dim baseStr As String = <string>INSERT INTO GZSTCONTAINERRECORD(GZSTCONTAINERRECORDID,CONTAINERID,STDATE,SAMPLENO,CREATEDATE,CREATEEMPLOYEEID)
	                                    VALUES('{0}','{1}',to_date('{2}','yyyy-MM-dd'),'{3}',sysdate,'{4}')</string>
            arrList.Add(String.Format(baseStr, GZSTCONTAINERRECORDID, para("CONTAINERID"), para("STDATE"), para("SAMPLENO"), para("CREATEEMPLOYEEID")))
        Else
            GZSTCONTAINERRECORDID = dt.Rows(0)("GZSTCONTAINERRECORDID").ToString
        End If
        Dim dgStr As String = <string> INSERT INTO GZSTCONTAINERRECORDDETAIL(GZSTCONTAINERRECORDDETAILID,GZSTCONTAINERRECORDID,DRAWINGNO,CREATEDATE,CREATEEMPLOYEEID)
	                            VALUES('{0}','{1}','{2}',sysdate,'{3}')</string>
        arrList.Add(String.Format(dgStr, Guid.NewGuid().ToString, GZSTCONTAINERRECORDID, para("DrawingNo"), para("CREATEEMPLOYEEID")))

        Return DatabaseHelper.ExecuteSqlListTran(arrList)
    End Function

    ''' <summary>
    ''' 删除--渗碳炉批记录（图号）
    ''' </summary>
    ''' <param name="IDS"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function DeleteDrawingNo(ByVal IDS As String) As Boolean
        Dim deleteStr As String = <string>delete FROM GZSTCONTAINERRECORDDETAIL where GZSTCONTAINERRECORDDETAILID IN('{0}')</string>
        Return DatabaseHelper.ExecuteSql(String.Format(deleteStr, IDS.Replace(",", "','"))) > 0
    End Function

End Class
